package com.zeroxml.cms.web.action;

import net.sourceforge.stripes.action.*;
import com.zeroxml.cms.util.Constant;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: cjp
 * Date: 2007-9-9
 * Time: 20:29:17
 */
public class BaseAction implements ActionBean {
    protected ActionBeanContext actionBeanContext;
    public void setContext(ActionBeanContext actionBeanContext) {
        this.actionBeanContext=actionBeanContext;
    }

    public ActionBeanContext getContext() {
        return this.actionBeanContext;
    }

    protected long getUserId(){
        SessionUser sessionUser=getSessionUser();
        if(sessionUser==null) return 0;
        return sessionUser.getId();
    }

    protected SessionUser getSessionUser(){
        return (SessionUser) actionBeanContext.getRequest().getSession().getAttribute(Constant.SESSION_USER);
    }

    protected void login(long userId,String name){
        actionBeanContext.getRequest().getSession().setAttribute(Constant.SESSION_USER,new SessionUser(userId,name));
    }
    protected HttpServletRequest getRequest(){
        return actionBeanContext.getRequest();
    }
    protected HttpServletResponse getResponse(){
        return actionBeanContext.getResponse();
    }

    @DontValidate
    public Resolution getCmsResolution(String view) {
        return new ForwardResolution("/WEB-INF/view/cms/" + view + ".jsp");
    }

    @DontValidate
    public Resolution getAdminResolution(String view) {
        return new ForwardResolution("/WEB-INF/view/admin/" + view + ".jsp"); 
    }
}
